/*
 * Created on 2005-6-6
 *
 *  To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.dcivision.dms.web;

import java.sql.Connection;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionMapping;

import com.dcivision.dms.bean.DmsRoot;
import com.dcivision.dms.core.DocumentRetrievalManager;
import com.dcivision.dms.dao.DmsRootDAObject;
import com.dcivision.framework.ApplicationException;
import com.dcivision.framework.GlobalConstant;
import com.dcivision.framework.SessionContainer;
import com.dcivision.framework.SystemFunctionConstant;
import com.dcivision.framework.TextUtility;
import com.dcivision.framework.web.AbstractActionForm;
import com.dcivision.framework.web.AbstractMaintAction;

/**
 * @author Anson.mo
 *
 * To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class MaintDmsPublicRootInfoAction extends AbstractMaintAction {
  public MaintDmsPublicRootInfoAction(){
   super(); 
  }

	/* (non-Javadoc)
	 * @see com.dcivision.framework.web.AbstractAction#getFunctionCode()
	 */
	public String getFunctionCode() {		
		return (SystemFunctionConstant.DMS_PUBLIC_FOLDER);
	}

	/* (non-Javadoc)
	 * @see com.dcivision.framework.web.AbstractAction#getMajorDAOClassName()
	 */
	public String getMajorDAOClassName() {
		
		return ("com.dcivision.dms.dao.DmsRootDAObject");
	}
  public void selectRecord(ActionMapping mapping, AbstractActionForm form, HttpServletRequest request, HttpServletResponse response) throws ApplicationException {
    MaintDmsPublicRootInfoForm publicRootInfoForm = (MaintDmsPublicRootInfoForm)form;       
    SessionContainer sessionContainer = this.getSessionContainer(request);
    Connection conn = this.getConnection(request);    
    DmsRootDAObject dsmRootDao = new DmsRootDAObject(sessionContainer,conn); 
    DmsRoot dmsRootBean = (DmsRoot)dsmRootDao.getObjectByID(TextUtility.parseIntegerObj(publicRootInfoForm.getRootID()));
    DocumentRetrievalManager docRetrievalManager = new DocumentRetrievalManager(sessionContainer, conn);
    Integer activeNoOfFile=docRetrievalManager.totalNoOfFileUnderRoot(GlobalConstant.RECORD_STATUS_ACTIVE,(dmsRootBean).getID() );
    Integer inactiveNoOfFile=docRetrievalManager.totalNoOfFileUnderRoot(GlobalConstant.RECORD_STATUS_INACTIVE,(dmsRootBean).getID() );
    Double activeFileSize=docRetrievalManager.totalFileSizeUnderRoot(GlobalConstant.RECORD_STATUS_ACTIVE,(dmsRootBean).getID() );
    String displayActiveFileSize=TextUtility.formatStorageSize(activeFileSize, "KB");
    Double inactiveFileSize=docRetrievalManager.totalFileSizeUnderRoot(GlobalConstant.RECORD_STATUS_INACTIVE,(dmsRootBean).getID() );
    String displayInactiveFileSize=TextUtility.formatStorageSize(inactiveFileSize, "KB");
    publicRootInfoForm.setActiveNoOfFile(activeNoOfFile.toString());
    publicRootInfoForm.setInactiveNoOfFile(inactiveNoOfFile.toString());
    publicRootInfoForm.setActiveFileSize(displayActiveFileSize);
    publicRootInfoForm.setInactiveFileSize(displayInactiveFileSize);
    publicRootInfoForm.setFormData(dmsRootBean);
  }

}
